package org.finesys.quartz.support;

import lombok.extern.slf4j.Slf4j;
import org.finesys.common.core.util.SpringContextHolder;
import org.finesys.common.quartz.core.constants.JobTypeQuartzEnum;
import org.finesys.common.quartz.core.exception.TaskException;
import org.springframework.util.StringUtils;

@Slf4j
public class TaskInvokeServiceFactory {

    /**
     * 根据类型获取处理服务类
     */
    public static TaskInvokeService taskInvokeService(String jobType) {
        if (!StringUtils.hasText(jobType)) {
            log.info("获取TaskInvokeService传递参数有误，jobType:{}", jobType);
            throw new TaskException(String.format("获取TaskInvokeService传递参数有误，jobType:%s", jobType));
        }
        if (JobTypeQuartzEnum.JAVA.getType().equals(jobType)) {
            return SpringContextHolder.getBean(TaskInvokeJavaClassServiceImpl.class);
        }
        if (JobTypeQuartzEnum.SPRING_BEAN.getType().equals(jobType)) {
            return SpringContextHolder.getBean(TaskInvokeSpringBeanServiceImpl.class);
        }
        if (JobTypeQuartzEnum.REST.getType().equals(jobType)) {
            return SpringContextHolder.getBean(TaskInvokeRestServiceImpl.class);
        }
        if (JobTypeQuartzEnum.JAR.getType().equals(jobType)) {
            return SpringContextHolder.getBean(TaskInvokeJarServiceImpl.class);
        }
        return null;
    }
}
